package com.dk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dk.dto.SpecDTO;
import com.dk.dto.SpecOptionDTO;
import com.dk.entity.DtRecycleNearby;
import com.dk.entity.DtSpecification;
import com.dk.entity.DtSpecificationOption;
import com.dk.mapper.DtRecycleNearbyMapper;
import com.dk.mapper.DtSpecificationMapper;
import com.dk.mapper.DtSpecificationOptionMapper;
import com.dk.service.IDtRecycleNearbyService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dk.vo.SpecVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 商品表，SKU表 服务实现类
 * </p>
 *
 * @author Lebron
 * @since 2021-12-21
 */
@Service
public class DtRecycleNearbyServiceImpl extends ServiceImpl<DtRecycleNearbyMapper, DtRecycleNearby> implements IDtRecycleNearbyService {
    @Autowired
    private DtSpecificationMapper specificationMapper;
    @Autowired
    private DtSpecificationOptionMapper optionMapper;

    @Override
    public SpecVO selectSpec(Integer id) {
        DtSpecification dtSpecification = specificationMapper.selectById(id);
        SpecDTO specDTO = new SpecDTO();
        BeanUtils.copyProperties(dtSpecification,specDTO);
        QueryWrapper<DtSpecificationOption> wrapper = new QueryWrapper<>();
        wrapper.eq("spec_id",id);
        List<DtSpecificationOption> optionList = optionMapper.selectList(wrapper);
        List<SpecOptionDTO> specOptionDTOS = optionList.stream().map(s -> {
            SpecOptionDTO specOptionDTO = new SpecOptionDTO();
            BeanUtils.copyProperties(s, specOptionDTO);
            return specOptionDTO;
        }).collect(Collectors.toList());
        SpecVO specVO = new SpecVO();
        specVO.setSpecDTO(specDTO);
        specVO.setSpecOptionDTOList(specOptionDTOS);

        return specVO;
    }
}
